import '../css/bootstrap.min.css';
import '../css/magnific-popup.css';
import '../css/font-awesome.min.css';
import '../css/style.css';
import './global.js';
import './bootstrap.min.js';
import './jquery.magnific-popup.js';

if(G.CONST.LANG_CN == G.language.getCustomerLanguage()){
	console.log("load cn menu");
    require('./menu_cn.js');
}else{
	console.log("load en menu");
	require('./menu_en.js');
}

import 'owl.carousel/dist/assets/owl.carousel.css';
import 'owl.carousel';
import header from '../tpl/header.hbs';
import footer from '../tpl/footer.hbs';


$(document).ready(function(){
	
	let nav = header({"menus":G.MENUS});
	$("#nav").append(nav);
    $("body").append(footer()); 
	$("#preloader").delay(600).fadeOut();
	initLanguageButton();

	///////////////////////////
	// Smooth scroll
	$("#nav .main-nav a[href^='#']").on('click', function(e) {
		e.preventDefault();
		var hash = this.hash;
		$('html, body').animate({
			scrollTop: $(this.hash).offset().top
		}, 600);
	});

	$('#back-to-top').on('click', function(){
		$('body,html').animate({
			scrollTop: 0
		}, 600);
	});

	///////////////////////////
	// Btn nav collapse
	$('#nav .nav-collapse').on('click', function() {
		$('#nav').toggleClass('open');
	});

	///////////////////////////
	// Mobile dropdown
	$('.has-dropdown a').on('click', function() {
		$(this).parent().toggleClass('open-drop');
	});

	///////////////////////////
	// On Scroll
	$(window).on('scroll', function() {
		var wScroll = $(this).scrollTop();

		// Fixed nav
		wScroll > 1 ? $('#nav').addClass('fixed-nav') : $('#nav').removeClass('fixed-nav');

		// Back To Top Appear
		wScroll > 700 ? $('#back-to-top').fadeIn() : $('#back-to-top').fadeOut();
	});

	///////////////////////////
	// magnificPopup
	$('.work').magnificPopup({
		delegate: '.lightbox',
		type: 'image'
	});

	///////////////////////////
	// Owl Carousel
	$('#about-slider').owlCarousel({
		items:1,
		loop:true,
		margin:15,
		nav: true,
		navText : ['<i class="fa fa-angle-left"></i>','<i class="fa fa-angle-right"></i>'],
		dots : true,
		autoplay : true,
		animateOut: 'fadeOut'
	});

	$('#testimonial-slider').owlCarousel({
		loop:true,
		margin:15,
		dots : true,
		nav: false,
		autoplay : true,
		responsive:{
			0: {
				items:1
			},
			992:{
				items:2
			}
		}
	});
});

function switchLanguage(language){
	/*var activeBtn = "";
	var inActiveBtn = "";
	if(G.CONST.LANG_CN == language){
    	console.log("load cn menu");
  	    require('./menu_cn.js');
  	    activeBtn = "#lang_cn";
  	    inActiveBtn = "#lang_en";
    }else{
	   console.log("load en menu");
	   require('./menu_en.js');
	   activeBtn = "#lang_en";
  	   inActiveBtn = "#lang_cn";
    }*/
    G.language.setCustomerLanguage(language);
    //$("#nav").html("");
   	//var nav = header({"menus":G.MENUS});
    //$("#nav").append(nav);
    
    //initLanguageButton();
    window.location.reload();
}

function initLanguageButton(){
	let language = G.language.getCustomerLanguage();
	let activeBtn = "";
	if(G.CONST.LANG_CN == language){
  	    activeBtn = "#lang_cn";
    }else{
	   activeBtn = "#lang_en";
    }
    $(activeBtn).addClass("active");
	$("#lang_cn").on('click',function(){
    	console.log("switch language to CN");
    	switchLanguage(G.CONST.LANG_CN);
    	
    });
    $("#lang_en").on('click',function(){
    	console.log("switch language to EN");
    	switchLanguage(G.CONST.LANG_EN);
    });
}